package com.boss.salary.controller;

import com.boss.api.dto.ApiResultDTO;
import com.boss.common.base.BasicinfoBaseController;
import com.boss.common.entity.PageDTO;
import com.boss.common.util.PageUtils;
import com.boss.framework.dto.PaginationDTO;
import com.boss.salary.entity.NotInPayment;
import com.boss.salary.service.INotInPaymentService;
import com.boss.sys.ca.user.dto.UserDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <br>Title: 首页
 * <br>Description:
 * <br>Author:
 * <br>Date:
 */
@RestController
@RequestMapping("/notInPaymentController")
public class NotInPaymentController extends BasicinfoBaseController {
    /**
     * 引入日志框架常量
     */
    private final static Logger logger = LoggerFactory.getLogger(HomeController.class);

    @Autowired
    private INotInPaymentService notInPaymentService;

    @GetMapping("/getNotInPayment")
    public ApiResultDTO getNotInPayment(@RequestHeader("tokenid") String tokenid,
                                        @RequestParam(value = "page") String page,
                                        @RequestParam(value = "limit") String limit) {
        try {
            UserDTO userDTO = getUser(tokenid);
            PaginationDTO paginationDTO = PageUtils.buildPaginationDTOPage(page, limit);
            PageDTO<NotInPayment> pageDTO = notInPaymentService.queryNotInPaymentPage(paginationDTO, userDTO.getProvince());
            return ApiResultDTO.success(pageDTO,null);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "查询异常");
        }
    }


    @PostMapping("/saveNotInPayment")
    public ApiResultDTO saveNotInPayment(@RequestHeader("tokenid") String tokenid,
                                         @RequestBody NotInPayment notInPayment) {
        try {
            UserDTO userDTO = getUser(tokenid);
            String province = userDTO.getProvince();
            notInPayment.setMof_div_code(province);
            notInPaymentService.submitNotIn(notInPayment);
            return ApiResultDTO.success(null);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "保存异常");
        }
    }

    @PostMapping("/deleteNotInPayment")
    public ApiResultDTO deleteNotInPayment(@RequestHeader("tokenid") String tokenid,
                                         @RequestBody NotInPayment notInPayment) {
        try {
            UserDTO userDTO = getUser(tokenid);
            String province = userDTO.getProvince();
            notInPayment.setMof_div_code(province);
            notInPaymentService.deleteNotInPayment(notInPayment);
            return ApiResultDTO.success(null);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return ApiResultDTO.error(ERROR_RSCODE, "删除异常");
        }
    }

}
